package com.lagou.sqlSession;

import com.lagou.config.XMLConfigBuilder;
import com.lagou.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream in) throws PropertyVetoException, DocumentException {
        //第一：使用dom4j解析sqlMapConfig.xml，将解析出来的内容 封装到Configuration对象中
        XMLConfigBuilder xmlConfigBuilder= new XMLConfigBuilder();
        Configuration configuration= xmlConfigBuilder.parseConfig(in);

        //第二：创建sqlSessionFactory对象：工厂类：生成sqlSession会话对象
        DefaultSqlSessionFactory defaultSqlSessionFactory = new DefaultSqlSessionFactory(configuration);


        return defaultSqlSessionFactory;

    }
}
